package com.test.demo1.service.impl;
import com.github.pagehelper.PageHelper;
import com.test.demo1.bean.CodeSnippets;
import com.test.demo1.common.BaseServiceImpl;
import com.test.demo1.common.PageRequest;
import com.test.demo1.mapper.CodeSnippetsMapper;
import com.test.demo1.service.CodeSnippetsService;
import com.test.demo1.util.SnowflakeIdGenerator;
import org.springframework.stereotype.Service;
import java.util.List;
import com.github.pagehelper.PageInfo;
import java.math.BigInteger;
/**
 * (CodeSnippets)表服务实现类
 *
 * @author makejava
 * @since 2025-07-22 21:53:55
 */
@Service
public class CodeSnippetsServiceImpl extends BaseServiceImpl<CodeSnippets,BigInteger> implements CodeSnippetsService {
    
    private final CodeSnippetsMapper codeSnippetsMapper;
    public CodeSnippetsServiceImpl(CodeSnippetsMapper codeSnippetsMapper){
    this.codeSnippetsMapper=codeSnippetsMapper;
    }
    /**
     * 分页查询
     *
     * @param codeSnippets 筛选条件
     * @return 查询结果
     */
    @Override
    public PageInfo<CodeSnippets> queryByPage(PageRequest<CodeSnippets> request) {
    CodeSnippets requestParam = request.getParam();
        if (requestParam==null){
            requestParam=new CodeSnippets();
        }
        PageHelper.startPage(request.getPageIndex(),request.getPageSize());
        List<CodeSnippets> list =codeSnippetsMapper.queryAll(requestParam);
        return new PageInfo<>(list);
    }
    
     @Override
    public void saveOrUpdate(CodeSnippets request) {
        
            if (request.getId()==null){
                request.setId(SnowflakeIdGenerator.nextId());
                //saveOrUpdate(request);
                mapper.insertSelective(request);
                return;
            }
            updateById(request);
    }
    
    @Override
    public void delete(CodeSnippets codeSnippets) {
        mapper.delete(codeSnippets);
    }

    @Override
    public void insertBatch(CodeSnippets codeSnippets, List<CodeSnippets> codeSnippetss) {
        codeSnippetsMapper.insertBatch(codeSnippets,codeSnippetss);
    }
}
